package com.ocm.tourism.core.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.TableGenerator;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Configurable;

@Entity
@Configurable
public class Room {

   @NotEmpty
   @NotNull
   @Size(max = 150)
   private String name;

   @NotEmpty
   @NotNull
   @Size(max = 50)
   private String typeRoom;

   private Double price;

   @ManyToOne
   private CommonItems currency; 

   @ManyToOne
   private Hotel hotel;

   public String toString() {
      return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
   }
   
   @Id
   @GeneratedValue(strategy=GenerationType.TABLE,generator="GEN_ROOM")
   @TableGenerator(name = "GEN_ROOM", table = "SEQUENCE_LIST", allocationSize = 1, initialValue = 1, pkColumnName = "NAME", valueColumnName = "NEXT_SEQUENCE", pkColumnValue = "ROOM")
   private Long id;

   @Version
   @Column(name = "version")
   private Integer version;

   public Long getId() {
      return this.id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public Integer getVersion() {
      return this.version;
   }

   public void setVersion(Integer version) {
      this.version = version;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getTypeRoom() {
      return typeRoom;
   }

   public void setTypeRoom(String typeRoom) {
      this.typeRoom = typeRoom;
   }

   public Double getPrice() {
      return price;
   }

   public void setPrice(Double price) {
      this.price = price;
   }

   public CommonItems getCurrency() {
      return currency;
   }

   public void setCurrency(CommonItems currency) {
      this.currency = currency;
   }

   public Hotel getHotel() {
      return hotel;
   }

   public void setHotel(Hotel hotel) {
      this.hotel = hotel;
   }

   @Override
   public boolean equals(Object obj) {
      Room objCompare = (Room) obj;
      if (objCompare.getId()!=null && this.getId()!=null){
         return objCompare.getId().longValue() == this.getId().longValue();
      }
      return super.equals(obj);
   }
}
